#!/usr/bin/env python
# coding: utf-8

# <font size="6"><center>高校信息处理</center></font>

# ## 目标：对高校数据、专业数据_专科(高职)、专业数据_本科数据进行分析
# - 全国各省高校情况  
# 
# - 全国各省高校热度情况分析  
# 
# - 专业学科与薪酬关系  
# 
# - 热门专业分析  
# 
# - 专业就业行业分布情况分析  

# ## 准备工作
# - 模块导入
# - 数据读取
# - 数据预处理

# In[38]:


# 导入所需模块
import pandas as pd
import plotly as py
import numpy as np


# In[2]:


# 读取数据
university = pd.read_csv('./高校数据.csv',encoding='gbk')
junior = pd.read_csv('./专业数据_专科(高职).csv',encoding='gbk')
regular = pd.read_csv('./专业数据_本科.csv',encoding='gbk')


# In[3]:


# 对数据进行处理
university = university.loc[:,['name','nature_name','province_name','address','belong',
                         'city_name', 'dual_class_name','f211','f985','level_name' ,
                         'type_name','view_month_number','view_total_number',
                         'view_week_number','rank']]


# In[4]:


c_name = ['大学名称','办学性质','省份','地址','隶属','城市','高校层次',
          '211院校','985院校','级别','类型','月访问量','总访问量','周访问量','排名']


# In[5]:


university.columns = c_name


# In[6]:


e_name = ['name','limit_year','level1_name','level2_name','level3_name',
          'degree', 'salaryavg','girl_rate','view_week','view_month','view_total']


# In[7]:


regular = regular.loc[:,e_name]


# In[8]:


c_name2 = ['专业名称','学制','一级名称','二级名称','三级名称','学位',
           '平均薪资','女生比例','周访问量','月访问量','总访问量']


# In[9]:


regular.columns = c_name2
regular


# In[10]:


junior = junior.loc[:,e_name]


# In[11]:


junior.columns = c_name2
junior


# In[12]:


# 访问量排序 sort_values ascending
university.sort_values(by='总访问量',ascending=False).head()


# In[13]:


university.shape


# ## 全国各省高校情况

# ### 全国各省高校数量

# In[14]:


university['高校总数'] = 1
university.fillna({'高校层次': '非双一流'},inplace=True)
university_by_province = university.pivot_table(index=['省份','高校层次'],
                                                 values='高校总数',aggfunc='count')
university_by_province.reset_index(inplace=True)
university_by_province.sort_values(by=['高校总数'],ascending=False,inplace=True)
university_by_province


# In[15]:


import plotly.express as px
fig = px.bar(university_by_province, 
             x="省份", 
             y="高校总数", 
             color="高校层次")
fig.update_layout(
    title='全国各省高校数量',
    xaxis_title="省份",
    yaxis_title="高校总数",
    template='ggplot2',
    font=dict(
        size=12,
        color="Black",        
    ),
    margin=dict(l=40, r=20, t=50, b=40),
    xaxis=dict(showgrid=False),
    yaxis=dict(showgrid=False),
    plot_bgcolor="#fafafa",
    legend=dict(yanchor="top",
    y=0.8,
    xanchor="left",
    x=0.78)
)
fig.show()


# In[16]:


py.offline.plot(fig, filename="全国各省高校数量.html",auto_open=False)
with open("全国各省高校数量.html", encoding="utf8", mode="r") as f:
    plot_all1 = "".join(f.readlines())


# ### 全国高校地理分布图

# In[17]:


df = pd.read_excel('./全国省市区行政区划.xlsx',header=1)
df_l = df.query("层级==2").loc[:,['全称','经度','纬度']]
df_l


# In[18]:


df_l = df_l.reset_index(drop=True).rename(columns={'全称':'城市'})
df_l


# In[19]:


# merge方法 pivot方法
df7 = university.pivot_table('大学名称','城市',aggfunc='count')
df7 = df7.merge(df_l,on='城市',how='left')
df7


# In[20]:


df7.sort_values(by='大学名称',ascending=False)


# In[21]:


import plotly.graph_objects as go
import pandas as p
df7['text'] = df7['城市'] + '<br>大学总数 ' + (df7['大学名称']).astype(str)+'个'
limits = [(0,10),(11,20),(21,50),(51,100),(101,200)]
colors = ["royalblue","crimson","lightseagreen","orange","red"]
cities = []
scale =.08

fig = go.Figure()

for i in range(len(limits)):
    lim = limits[i]
    df_sub = df7[df7.大学名称.map(lambda x: lim[0] <= x <= lim[1])]
    fig.add_trace(go.Scattergeo(
        locationmode = 'ISO-3',
        lon = df_sub['经度'],
        lat = df_sub['纬度'],
        text = df_sub['text'],
        marker = dict(
            size = df_sub['大学名称'],
            color = colors[i],
            line_color='rgb(40,40,40)',
            line_width=0.5,
            sizemode = 'area'
        ),
        name = '{0} - {1}'.format(lim[0],lim[1])))

fig.update_layout(
        title_text = '全国高校地理分布图',
        showlegend = True,
        geo = dict(
            scope = 'asia',
            landcolor = 'rgb(217, 217, 217)',
        ),
        template='ggplot2',
        font=dict(
        size=12,
        color="Black",),
    legend=dict(yanchor="top",
    y=1.,
    xanchor="left",
    x=1)
    )

fig.show()


# In[22]:


py.offline.plot(fig, filename="全国高校地理分布图.html",auto_open=False)
with open("全国高校地理分布图.html", encoding="utf8", mode="r") as f:
    plot_all2 = "".join(f.readlines())


# ## 全国各省高校热度情况分析

# ### 普通本科全国高校热度TOP15

# In[23]:


## Plot Region wise countt of countries and average ladder score
import plotly.graph_objs as go
fig=go.Figure()
df3 = university.sort_values(by='总访问量',ascending=False)
fig.add_trace(go.Bar(
    x=df3.loc[:15,'大学名称'],
    y=df3.loc[:15,'总访问量'],
    name='总访问量',
    marker_color='#009473',
    textposition='inside',
    yaxis='y1'
))
fig.add_trace(go.Scatter(
    x=df3.loc[:15,'大学名称'],
    y=df3.loc[:15,'周访问量'],
    name='周访问量',
    mode='markers+text+lines',
    marker_color='black',
    marker_size=10,
    textposition='top center',
    line=dict(color='orange',dash='dash'),
    yaxis='y2'

))
fig.update_layout(
    title='全国高校热度TOP15',
    xaxis_title="大学名称",
    yaxis_title="总访问量",
    template='ggplot2',
    font=dict(
        size=12,
        color="Black",
        
    ),
    xaxis=dict(showgrid=False),
    yaxis=dict(showgrid=False),
    plot_bgcolor="#fafafa",
    yaxis2=dict(showgrid=True,overlaying='y',side='right',title='周访问量'),
    legend=dict(yanchor="top",
    y=1.15,
    xanchor="left",
    x=0.8)
)

fig.show()


# In[24]:


py.offline.plot(fig, filename="普通本科全国高校热度TOP15.html",auto_open=False)
with open("普通本科全国高校热度TOP15.html", encoding="utf8", mode="r") as f:
    plot_all3 = "".join(f.readlines())


# ### 全国专科(高职)院校热度TOP15

# In[25]:


## Plot Region wise countt of countries and average ladder score
import plotly.graph_objs as go
fig=go.Figure()
df4 = university.query("级别 =='专科（高职）'").sort_values(by='总访问量',ascending=False).iloc[:15,:]
fig.add_trace(go.Bar(
    x=df4['大学名称'],
    y=df4['总访问量'],
    name='总访问量',
    marker_color='#009473',
    textposition='inside',
    yaxis='y1'
))
fig.add_trace(go.Scatter(
    x=df4['大学名称'],
    y=df4['周访问量'],
    name='周访问量',
    mode='markers+text+lines',
    marker_color='black',
    marker_size=10,
    textposition='top center',
    line=dict(color='orange',dash='dash'),
    yaxis='y2'

))
fig.update_layout(
    title='全国专科(高职)院校热度TOP15',
    xaxis_title="高校名称",
    yaxis_title="总访问量",
    template='ggplot2',
    font=dict(
        size=12,
        color="Black",
        
    ),
    xaxis=dict(showgrid=False),
    yaxis=dict(showgrid=False),
    plot_bgcolor="#fafafa",
    yaxis2=dict(showgrid=True,overlaying='y',side='right',title='周访问量'),
    legend=dict(yanchor="top",
    y=1.15,
    xanchor="left",
    x=0.8)
)

fig.show()


# In[26]:


py.offline.plot(fig, filename="全国专科(高职)院校热度TOP15.html",auto_open=False)
with open("全国专科(高职)院校热度TOP15.html", encoding="utf8", mode="r") as f:
    plot_all15 = "".join(f.readlines())


# ### 全国高校热度TOP10省份的前三名

# In[27]:


df9 = university.loc[:,['省份','大学名称','总访问量']]
df9


# In[28]:


df9['前三'] = df9.drop_duplicates()['总访问量'].groupby(by=df9['省份']).rank(method='first', ascending=False)
# 筛选前三名
df_10 = df9[df9['前三'].map(lambda x: True if x < 4 else False)]
# 转换数据类型
df_10['前三'] = df_10.前三.astype(int)
df_pt = df_10.pivot_table(values='总访问量',index='省份',columns='前三')
# 排序
df_pt_2 = df_pt.sort_values(by=1,ascending=False)[:10]
df_pt_2


# In[29]:


df_labels_1 = df9[df9.前三 == 1].set_index('省份').loc[df_pt_2.index,'大学名称'][:10]
df_labels_1


# In[30]:


df_labels_2 = df9[df9.前三 == 2].set_index('省份').loc[df_pt_2.index,'大学名称'][:10]
df_labels_2


# In[31]:


df_labels_3 = df9[df9.前三 == 3].set_index('省份').loc[df_pt_2.index,'大学名称'][:10]
df_labels_3


# In[32]:


x = df_pt_2.index
fig = go.Figure()
fig.add_trace(go.Bar(
    x=x,
    y=df_pt_2[1],
    name='热度第一',
    marker_color='indianred',
    textposition='inside',
    text=df_labels_1.values,
    textangle = 90
))
fig.add_trace(go.Bar(
    x=x,
    y=df_pt_2[2],
    name='热度第二',
    marker_color='lightsalmon',
    textposition='inside',
    text=df_labels_2.values,
    textangle = 90
))
fig.add_trace(go.Bar(
    x=x,
    y=df_pt_2[3],
    name='热度第三',
    marker_color='lightpink',
    textposition='inside',
    text=df_labels_3.values,
    textangle = 90
))

# Here we modify the tickangle of the xaxis, resulting in rotated labels.
fig.update_layout(barmode='group', xaxis_tickangle=-45)
fig.update_layout(
    title='全国高校热度TOP10省份的前三名',
    xaxis_title="省份",
    yaxis_title="总访问量",
    template='ggplot2',
    font=dict(
        size=12,
        color="Black"),
    barmode='group', xaxis_tickangle=-45    
    )
fig.show()


# In[33]:


py.offline.plot(fig, filename="全国高校热度TOP10省份的前三名.html",auto_open=False)
with open("全国高校热度TOP10省份的前三名.html", encoding="utf8", mode="r") as f:
    plot_all10 = "".join(f.readlines())


# ### 北京高校热度TOP15

# In[34]:


df_bj = university.query("高校层次 == '双一流' and 城市== '北京市'").iloc[:15,:]
## Plot Region wise countt of countries and average ladder score
import plotly.graph_objs as go
fig=go.Figure()
df3 = university.sort_values(by='总访问量',ascending=False)
fig.add_trace(go.Bar(
    x=df_bj['大学名称'],
    y=df_bj['总访问量'],
    name='总访问量',
    marker_color='#009473',
    textposition='inside',
    yaxis='y1'
))
fig.add_trace(go.Scatter(
    x=df_bj['大学名称'],
    y=df_bj['周访问量'],
    name='周访问量',
    mode='markers+text+lines',
    marker_color='black',
    marker_size=10,
    textposition='top center',
    line=dict(color='orange',dash='dash'),
    yaxis='y2'

))
fig.update_layout(
    title='北京高校热度TOP15',
    xaxis_title="大学名称",
    yaxis_title="总访问量",
    template='ggplot2',
    font=dict(
        size=12,
        color="Black",
        
    ),
    xaxis=dict(showgrid=False),
    yaxis=dict(showgrid=False),
    plot_bgcolor="#fafafa",
    yaxis2=dict(showgrid=True,overlaying='y',side='right',title='周访问量'),
    legend=dict(yanchor="top",
    y=1.15,
    xanchor="left",
    x=0.78)
)

fig.show()


# In[35]:


py.offline.plot(fig, filename="北京高校热度TOP15.html",auto_open=False)
with open("北京高校热度TOP15.html", encoding="utf8", mode="r") as f:
    plot_all16 = "".join(f.readlines())


# ## 专业学科与薪酬

# ### 本科学科、平均薪资与总访问量比例图

# In[36]:


regular.head()


# In[39]:


df14 = regular.copy()
df14['平均薪资'] = df14['平均薪资'].map(lambda x:np.nan if x==0 else x)
df14['女生比例'] = df14['女生比例'].map(lambda x:np.nan if x==0 else x)
for column in ['平均薪资','女生比例']:
    mean_val = int(df14[column].mean())
    df14[column].fillna(mean_val, inplace=True)
fig = px.sunburst(df14, 
                  path=['二级名称','三级名称'], 
                  values='总访问量',
                  color='平均薪资', 
#                   hover_data=['女神比例'],
                  color_continuous_scale='RdBu')
fig.update_layout(
    title='本科学科、平均薪资与总访问量比例图',
#     template='ggplot2',
    font=dict(
        size=12,
        color="Black",),
    plot_bgcolor="#fafafa",
)
fig.show()


# In[40]:


py.offline.plot(fig, filename="本科学科、平均薪资与总访问量比例图.html",auto_open=False)
with open("本科学科、平均薪资与总访问量比例图.html", encoding="utf8", mode="r") as f:
    plot_all17 = "".join(f.readlines())


# ### 工学学科、平均薪资与总访问量比例图

# In[41]:


df14 = regular.copy()
df14 = regular.query("二级名称 == '工学'")
df14['平均薪资'] = df14['平均薪资'].map(lambda x:np.nan if x==0 else x)
df14['女生比例'] = df14['女生比例'].map(lambda x:np.nan if x==0 else x)
for column in ['平均薪资','女生比例']:
    mean_val = int(df14[column].mean())
    df14[column].fillna(mean_val, inplace=True)
fig = px.sunburst(df14, 
                  path=['二级名称','三级名称'], 
                  values='总访问量',
                  color='平均薪资', 
#                   hover_data=['女神比例'],
                  color_continuous_scale='RdBu')
fig.update_layout(
    title='工学学科、平均薪资与总访问量比例图',
#     template='ggplot2',
    font=dict(
        size=12,
        color="Black",),
    plot_bgcolor="#fafafa",
)
fig.show()


# In[42]:


py.offline.plot(fig, filename="工学学科、平均薪资与总访问量比例图.html",auto_open=False)
with open("工学学科、平均薪资与总访问量比例图.html", encoding="utf8", mode="r") as f:
    plot_all_gongxue = "".join(f.readlines())


# ### 理学学科、平均薪资与总访问量比例图

# In[43]:


df14 = regular.copy()
df14 = regular.query("二级名称 == '理学'")
df14['平均薪资'] = df14['平均薪资'].map(lambda x:np.nan if x==0 else x)
df14['女生比例'] = df14['女生比例'].map(lambda x:np.nan if x==0 else x)
for column in ['平均薪资','女生比例']:
    mean_val = int(df14[column].mean())
    df14[column].fillna(mean_val, inplace=True)
fig = px.sunburst(df14, 
                  path=['二级名称','三级名称'], 
                  values='总访问量',
                  color='平均薪资', 
#                   hover_data=['女神比例'],
                  color_continuous_scale='RdBu')
fig.update_layout(
    title='理学学科、平均薪资与总访问量比例图.html',
#     template='ggplot2',
    font=dict(
        size=12,
        color="Black",),
    plot_bgcolor="#fafafa",
)
fig.show()


# In[44]:


py.offline.plot(fig, filename="理学学科、平均薪资与总访问量比例图.html",auto_open=False)
with open("理学学科、平均薪资与总访问量比例图.html", encoding="utf8", mode="r") as f:
    plot_all_lixue = "".join(f.readlines())


# ### 专科(高职)学科、平均薪资与总访问量比例图

# In[45]:


junior.head()


# In[46]:


df15 = junior.copy()
df15['平均薪资'] = df15['平均薪资'].map(lambda x:np.nan if x==0 else x)
df15['女生比例'] = df15['女生比例'].map(lambda x:np.nan if x==0 else x)
for column in ['平均薪资','女生比例']:
    mean_val = int(df15[column].mean())
    df15[column].fillna(mean_val, inplace=True)
    
fig = px.sunburst(df15, 
                  path=['二级名称', '三级名称'], 
                  values='总访问量',
                  color='平均薪资', 
                  hover_data=['女生比例'],
                  color_continuous_scale='RdBu')

fig.update_layout(
    title='专科(高职)学科、平均薪资与总访问量比例图',
#     template='ggplot2',
    font=dict(
        size=12,
        color="Black",),
    plot_bgcolor="#fafafa",
)
fig.show()


# In[47]:


py.offline.plot(fig, filename="专科(高职)学科、平均薪资与总访问量比例图.html",auto_open=False)
with open("专科(高职)学科、平均薪资与总访问量比例图.html", encoding="utf8", mode="r") as f:
    plot_all5 = "".join(f.readlines())


# ### 医药卫生大类学科、平均薪资与总访问量比例图

# In[48]:


df15 = junior.copy()
df15 = junior.query("二级名称 == '医药卫生大类'")
df15['平均薪资'] = df15['平均薪资'].map(lambda x:np.nan if x==0 else x)
df15['女生比例'] = df15['女生比例'].map(lambda x:np.nan if x==0 else x)
for column in ['平均薪资','女生比例']:
    mean_val = int(df15[column].mean())
    df15[column].fillna(mean_val, inplace=True)
    
fig = px.sunburst(df15, 
                  path=['二级名称', '三级名称'], 
                  values='总访问量',
                  color='平均薪资', 
                  hover_data=['女生比例'],
                  color_continuous_scale='RdBu')

fig.update_layout(
    title='医药卫生大类学科、平均薪资与总访问量比例图',
#     template='ggplot2',
    font=dict(
        size=12,
        color="Black",),
    plot_bgcolor="#fafafa",
)
fig.show()


# In[49]:


py.offline.plot(fig, filename="医药卫生大类学科、平均薪资与总访问量比例图.html",auto_open=False)
with open("医药卫生大类学科、平均薪资与总访问量比例图.html", encoding="utf8", mode="r") as f:
    plot_all_yiyao = "".join(f.readlines())


# ### 交通运输大类学科、平均薪资与总访问量比例图

# In[50]:


df15 = junior.copy()
df15 = junior.query("二级名称 == '交通运输大类'")
df15['平均薪资'] = df15['平均薪资'].map(lambda x:np.nan if x==0 else x)
df15['女生比例'] = df15['女生比例'].map(lambda x:np.nan if x==0 else x)
for column in ['平均薪资','女生比例']:
    mean_val = int(df15[column].mean())
    df15[column].fillna(mean_val, inplace=True)
    
fig = px.sunburst(df15, 
                  path=['二级名称', '三级名称'], 
                  values='总访问量',
                  color='平均薪资', 
                  hover_data=['女生比例'],
                  color_continuous_scale='RdBu')

fig.update_layout(
    title='交通运输大类学科、平均薪资与总访问量比例图',
#     template='ggplot2',
    font=dict(
        size=12,
        color="Black",),
    plot_bgcolor="#fafafa",
)
fig.show()


# In[51]:


py.offline.plot(fig, filename="交通运输大类学科、平均薪资与总访问量比例图.html",auto_open=False)
with open("交通运输大类学科、平均薪资与总访问量比例图.html", encoding="utf8", mode="r") as f:
    plot_all_yiyao = "".join(f.readlines())


# ## 热门专业分析

# ### 本科热门专业TOP20

# In[52]:


## Plot Region wise countt of countries and average ladder score
fig=go.Figure()
df11 = regular.sort_values(by='总访问量',ascending=False)[:20]
fig.add_trace(go.Bar(
    x=df11['专业名称'],
    y=df11['总访问量'],
    name='总访问量',
    marker_color='#009473',
    textposition='inside',
    yaxis='y1'
))
fig.add_trace(go.Scatter(
    x=df11['专业名称'],
    y=df11['周访问量'],
    name='周访问量',
    mode='markers+text+lines',
    marker_color='black',
    marker_size=10,
    textposition='top center',
    line=dict(color='orange',dash='dash'),
    yaxis='y2'

))
fig.update_layout(
    title='本科热门专业TOP20',
    xaxis_title="专业名称",
    yaxis_title="总访问量",
    template='ggplot2',
    font=dict(
        size=12,
        color="Black",
        
    ),
    xaxis=dict(showgrid=False),
    yaxis=dict(showgrid=False),
    plot_bgcolor="#fafafa",
    yaxis2=dict(showgrid=True,overlaying='y',side='right',title='周访问量'),
    legend=dict(yanchor="top",
    y=1.15,
    xanchor="left",
    x=0.78)
)

fig.show()


# In[53]:


py.offline.plot(fig, filename="本科热门专业TOP20.html",auto_open=False)
with open("本科热门专业TOP20.html", encoding="utf8", mode="r") as f:
    plot_all4 = "".join(f.readlines())


# ### 专科(高职)热门专业TOP20

# In[54]:


## Plot Region wise countt of countries and average ladder score
import plotly.graph_objs as go
fig=go.Figure()
df12 = junior.sort_values(by='总访问量',ascending=False)[:20]
fig.add_trace(go.Bar(
    x=df12['专业名称'],
    y=df12['总访问量'],
    name='总访问量',
    marker_color='#009473',
    textposition='inside',
    yaxis='y1'
))
fig.add_trace(go.Scatter(
    x=df12['专业名称'],
    y=df12['周访问量'],
    name='周访问量',
    mode='markers+text+lines',
    marker_color='black',
    marker_size=10,
    textposition='top center',
    line=dict(color='orange',dash='dash'),
    yaxis='y2'

))
fig.update_layout(
    title='专科(高职)热门专业TOP20',
    xaxis_title="专业名称",
    yaxis_title="总访问量",
    template='ggplot2',
    font=dict(
        size=12,
        color="Black",
        
    ),
    xaxis=dict(showgrid=False),
    yaxis=dict(showgrid=False),
    plot_bgcolor="#fafafa",
    yaxis2=dict(showgrid=True,overlaying='y',side='right',title='周访问量'),
    legend=dict(yanchor="top",
    y=1.15,
    xanchor="left",
    x=0.78)
)

fig.show()


# In[55]:


py.offline.plot(fig, filename="专科(高职)热门专业TOP20.html", auto_open=False)
with open("专科(高职)热门专业TOP20.html", encoding="utf8", mode="r") as f:
        plot_all5 = "".join(f.readlines())


# ## 专业就业行业分布情况分析

# ### 数学与应用数学就业行业分布

# In[56]:


professional_name = "数学与应用数据"
employment = [{"name": "教育培训",  "rate": 27.57},
                {"name": "金融投资",  "rate": 9.09},
                {"name": "IT软件",  "rate": 7.88},
                {"name": "互联网",  "rate": 5.00},
                {"name": "房地产",  "rate": 4.38},
                {"name": "电子技术",  "rate": 3.63},
                {"name": "系统集成",  "rate": 3.24},
                {"name": "快消",  "rate": 2.15},
                {"name": "批发零售",  "rate": 0.26},
                {"name": "其他行业",  "rate": 36.80}]
df_employment = pd.DataFrame(employment)
df_employment


# In[57]:


## Plot Region wise countt of countries and average ladder score
import plotly.graph_objs as go
fig=go.Figure()
fig.add_trace(go.Bar(
    x=df_employment['name'],
    y=df_employment['rate'],
    name='比率',
    marker_color='#20B2AA',
    textposition='outside',
    text=df_employment.rate,
))
fig.update_traces(texttemplate='%{text}%')
fig.update_layout(
    title='【数学与应用数学】就业行业分布',
    xaxis_title="就业行业",
    yaxis_title="就业百分比",
    template='ggplot2',
    font=dict(
        size=12,
        color="Black",),
    xaxis=dict(showgrid=False),
    yaxis=dict(showgrid=False),
    plot_bgcolor="#fafafa",
)

fig.show()


# In[58]:


py.offline.plot(fig, filename="【数学与应用数学】就业行业分布.html", auto_open=False)
with open("【数学与应用数学】就业行业分布.html", encoding="utf8", mode="r") as f:
    plot_all6 = "".join(f.readlines())


# ### 电磁场与无线技术就业岗位分布

# In[59]:


labels = ['电子/电器通用技术','通信工程','销售业务','项目管理/协调','测试','其他']
values = [24.70, 13.80,8.20, 4.90,3.10,45.30]
fig = go.Figure(data=[go.Pie(labels=labels, values=values, 
                             textinfo='label+percent',hole=.4)])
fig.update_layout(
    title='【电磁场与无线技术】就业岗位分布',
    template='seaborn',
    font=dict(
        size=12,
        color="Black",))
fig.show()


# In[60]:


py.offline.plot(fig, filename="【电磁场与无线技术】就业岗位分布.html",auto_open=False)
with open("【电磁场与无线技术】就业岗位分布.html", encoding="utf8", mode="r") as f:
    plot_all_dian = "".join(f.readlines())


# ### 计算机科学与技术就业岗位分布

# In[61]:


jobs = [['后端开发',14.2],
['技术支持',10.2],
['移动开发',6.7],
['销售业务',5.8],
['测试',5.3],
['其他',57.8]]


# In[62]:


df_jobs = pd.DataFrame(jobs,columns=['就业岗位','比例'])
df_jobs


# In[63]:


import plotly.graph_objects as go
labels = ['后端开发','技术支持','移动开发','销售业务','测试','其他']
values = [14.2, 10.2, 6.7, 5.8,5.3,57.8]
fig = go.Figure(data=[go.Pie(labels=labels, values=values, 
                             textinfo='label+percent',hole=.4)])
fig.update_layout(
    title='【计算机科学与技术】就业岗位分布',
    template='ggplot2',
    font=dict(
        size=12,
        color="Black",))
fig.show()


# In[64]:


py.offline.plot(fig, filename="【计算机科学与技术】就业岗位分布.html", auto_open=False)
with open("【计算机科学与技术】就业岗位分布.html", encoding="utf8", mode="r") as f:
    plot_all_jisuanji = "".join(f.readlines())


# ## 其他分析

# ### 全国高校按类别热度图

# In[65]:


df5 = university.loc[:,['城市','高校层次','211院校','985院校']]
df5['总数'] = 1
df5['211院校'] = df5['211院校'].map(lambda x: '是' if x == 1 else '否')


# In[66]:


df5['985院校'] = df5['985院校'].map(lambda x: '是' if x == 1 else '否')


# In[67]:


df6  =df5.pivot_table(index=['城市','985院校'],values='总数').reset_index()
df6


# In[68]:


df6.columns


# In[69]:


fig = px.scatter(university,
                 x="省份", y="类型",
                 size="总访问量"
                )
fig.update_layout(
    title='全国高校按类别热度图',
    xaxis_title="省份",
    yaxis_title="院校类型",
    template='ggplot2',
    font=dict(
        size=12,
        color="Black",),
    xaxis=dict(showgrid=False),
    yaxis=dict(showgrid=False),
    plot_bgcolor="#fafafa",
)
fig.show()


# In[70]:


import plotly.express as px
fig = px.imshow(university)
fig.show()


# ### 本科计算机类的平均薪资、女生比例和总访问量

# In[71]:


fig=go.Figure()
df18 = regular.query("三级名称 == '计算机类'")
# fig = px.scatter(df12[:30], x="专业名称", y="平均薪资", color="女神比例",
#                  size='总访问量', hover_data=['总访问量'])
fig = px.scatter(df18, x="专业名称", y="平均薪资", color="总访问量",
                 size='女生比例', hover_data=['女生比例'])
fig.update_layout(
    title='本科计算机类的平均薪资、女生比例和总访问量',
    template='ggplot2',
    font=dict(
        size=12,
        color="Black",),
    xaxis=dict(showgrid=False),
    yaxis=dict(showgrid=False),
    plot_bgcolor="#fafafa",
)
fig.show()


# ### 本科热门专业(TOP30)的平均薪资、女生比例和总访问量

# In[72]:


fig=go.Figure()
df12 = regular.query('平均薪资 != 0')
# fig = px.scatter(df12[:30], x="专业名称", y="平均薪资", color="女神比例",
#                  size='总访问量', hover_data=['总访问量'])
fig = px.scatter(df12[0:30], x="专业名称", y="平均薪资", color="总访问量",
                 size='女生比例', hover_data=['女生比例'])
fig.update_layout(
    title='本科热门专业(TOP30)的平均薪资、女生比例和总访问量',
    template='ggplot2',
    font=dict(
        size=12,
        color="Black",),
    xaxis=dict(showgrid=False),
    yaxis=dict(showgrid=False),
    plot_bgcolor="#fafafa",
)
fig.show()


# ### 本科冷门专业(TOP30)的平均薪资、女生比例和总访问量

# In[73]:


fig=go.Figure()
df12 = regular.query('平均薪资 != 0')
# fig = px.scatter(df12[:30], x="专业名称", y="平均薪资", color="女神比例",
#                  size='总访问量', hover_data=['总访问量'])
fig = px.scatter(df12[-30:], x="专业名称", y="平均薪资", color="总访问量",
                 size='女生比例', hover_data=['女生比例'])
fig.update_layout(
    title='本科冷门专业(TOP30)的平均薪资、女生比例和总访问量',
    template='ggplot2',
    font=dict(
        size=12,
        color="Black",),
    xaxis=dict(showgrid=False),
    yaxis=dict(showgrid=False),
    plot_bgcolor="#fafafa",
)
fig.show()


# In[ ]:




